package com.ham.mud.commands;

import com.ham.mud.ServerConnection;
import com.ham.mud.state.PlayingState;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * Created by hlucas on Jul 1, 2011 at 5:20:29 PM
 */
public class CommandsCommand extends PlayerCommand {
    @Override
    public void execute(ServerConnection connection, String[] params) {
        connection.printStart("Commands:");
        connection.println("----------------------------");
        List<String> list = new ArrayList<String>();
        List<PlayerCommand> listed = new ArrayList<PlayerCommand>(PlayingState.listedCommands);
        for(PlayerCommand playerCommand : listed) {
            list.add(playerCommand.getCommandName());
        }

        Set<String> keys = PlayingState.mappedCommands.keySet();
        list.addAll(keys);

        Collections.sort(list);
        for(String string : list) {
            connection.println(string);
        }
        
        connection.println("----------------------------");
        connection.printEnd();        
    }

    @Override
    protected String getCommandName() {
        return "commands";
    }
}
